package NG::Sys::Cfg;
use strict;
use warnings;
use utf8;

use Cwd qw(realpath);

use base 'Exporter';
my %configs;
our $path = "../cfg";
our @EXPORT = qw(config appconfig);

sub config {
	my ($name) = @_;
	$name ||= "main";
	my $config;
	if($config = $configs{$name}){
		return $config;
	}
	my $fn = $path."/".$name.".cfg";
	my $str = "";
	local *F;
	if(open F,$fn){
		binmode F,":utf8";
		local $/;
		$str = <F>;
		close F;
	}
	eval "\$config = {".$str."}";
	if($@){
		die "$fn: $@";
	}
	return $configs{$name} = $config;
}
sub appconfig{
	local $path = "../cfgapp";
	return config(@_);
}
1;
